package com.wangsd.web.sys.service;

import com.gitee.fastmybatis.core.query.Query;
import com.wangsd.web.sys.entity.SysPermission;
import com.wangsd.web.sys.mapper.SysPermissionMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SysPermissionService {
    @Resource
    SysPermissionMapper mapper;

    /**
     * 根据roleId查询所有权限
     * @param roleId
     * @return
     */
    List<SysPermission> selectByRoleId(Long roleId) {
        return mapper.selectByRoleId(roleId);
    }

    /**
     * 批量保存
     * @param buttonPermissionList
     * @return
     */
    public int saveBatch(List<SysPermission> buttonPermissionList) {
        return mapper.saveBatch(buttonPermissionList);
    }

    /**
     * 根据roleId删除所有权限
     * @param roleId
     * @return
     */
    public int deleteByRoleId(Long roleId) {
        Query query = new Query().eq("role_id", roleId);
        return mapper.deleteByQuery(query);
    }

    public int deleteBybuttonId(Long buttonId) {
        return mapper.deleteByQuery(new Query().eq("access_id", buttonId));
    }
}
